import tkinter as tk
def jisuan():
    flag = False
    f = -1
    s = 1
    i = 1
    while not flag:
        t = 1/(2*i+1)
        if t*4 < 0.0001:
            flag = True
        s = s + t*f
        f = -f
        i += 1
    lb2['text'] = '{:.4f}'.format(s*4)
# 建立窗口
win = tk.Tk()
win.title('圆周率计算')
win.geometry('280x150')
win.resizable(0, 0)
# 建立组件
lb1 = tk.Label(win, text = 'π精确到万分之一的结果：',font = ('微软雅黑', 11))
lb2 = tk.Label(win, text = ' ',font = ('微软雅黑', 12))
cmd = tk.Button(win, text = '计算', font = ('微软雅黑', 11),command = jisuan)
# 组件布局
lb1.grid(row=0, column=0,pady=20,padx=20)
lb2.grid(row=1, column=0)
cmd.grid(row=1,column=1)
# 接收窗口事件
win.mainloop()